var demo =
    {
    _topic: "topic://ACTIVEMQ.DEMO",

    sendMsg: function(text)
    {
        if (text != null && text.length>0 )
        {
            text=text.replace('<','&lt;');
            text=text.replace('>','&gt;');
            amq.sendMessage(this._topic, "<message>" + text + "</message>");
        }
    },

    rcvMsg: function(text)
    {
        var msg = text.childNodes[0].data;
        var msgPanel = $('msgs');
        msgPanel.innerHTML += msg + "<br/>";
    }
};

var demoBehaviour =
    {
    '#msg' : function(element)
    {
        element.setAttribute("autocomplete","OFF");
        element.onkeyup = function(ev)
        {
            var keyc = getKeyCode(ev);

            if (keyc == 13 || keyc == 10)
            {
                var text = $F('msg');
                $('msg').value='';
                demo.sendMsg(text);
                return false;
            }
            return true;
        }
    },

    '#sendBtn' : function(element)
    {
        element.onclick = function(event)
        {
            var text = $F('msg');
            $('msg').value='';
            demo.sendMsg(text);
        }
    }
};

amq.addListener('demo', demo._topic, demo.rcvMsg);
Behaviour.register(demoBehaviour);